package com.azkj.album.view.widgets.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.azkj.album.R;
import com.azkj.album.adapter.CategoryAdapter;
import com.azkj.album.dto.CategoryBean;
import com.azkj.album.utils.DensityUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.List;


public class ColorChooseDialog {


    public static final class Builder {

        private Context mContext;

        private RecyclerView category_list;
        private CategoryAdapter categoryAdapter;
        private OnClickListener mListener;

        private final Dialog dialog;


        public Builder(Context context) {
            this.mContext = context;
            View view = LayoutInflater.from(context).inflate(
                    R.layout.dialog_color_choose, null);
            category_list = view.findViewById(R.id.category_list);

            // 定义Dialog布局和参数
            dialog = new Dialog(context, R.style.MyDialog);
            dialog.setContentView(view);
            Window dialogWindow = dialog.getWindow();
            dialogWindow.setGravity(Gravity.CENTER);
            WindowManager.LayoutParams lp = dialogWindow.getAttributes();
            lp.x = 0;
            lp.y = 0;
            lp.width = (int) (DensityUtils.getScreenWidth(context));
            lp.height = (int) (DensityUtils.getScreenHeight(context));
            lp.gravity = Gravity.CENTER;
            dialogWindow.setAttributes(lp);

            categoryAdapter = new CategoryAdapter(R.layout.item_category_main);
            categoryAdapter.setOnItemClickListener((adapter, view1, position) -> mListener.onClick(dialog, position));
            category_list.setAdapter(categoryAdapter);
        }


        public Builder setOnClickListener(OnClickListener listener) {
            this.mListener = listener;
            return this;
        }

        public Builder setChoosetList(List<CategoryBean> datas) {
            if (null != categoryAdapter && null != datas) {
                categoryAdapter.setNewData(datas);
            }
            return this;
        }

        public Builder setChooseData(CategoryBean chooseData) {
            if (null != chooseData && categoryAdapter != null && null != categoryAdapter.getData()) {
                int position = categoryAdapter.getData().indexOf(chooseData);
                categoryAdapter.setCurPosition(position);
            }
            return this;
        }

        public Builder show() {
            dialog.show();
            return this;
        }


    }

    public interface OnClickListener {
        void onClick(Dialog dialog, int position);
    }


}
